from util import *
import pandas as pd




#统计不同服务的请求频率

def statistic_microservice_rt(group_item):
    root_dir=get_root_dir()
    dataset_dir=os.path.dirname(root_dir)+"/MS_data/data"
    dir="CallGraph"

    df_all=pd.DataFrame()
    tar_file_name=list_tar_files(os.path.join(dataset_dir,dir))
    for file in tar_file_name[:]:
        print(file)
        df_temp=read_csv_from_tar_gz(os.path.join(dataset_dir,dir)+"/"+file)
        # df_temp = pd.read_csv(os.path.join(dataset_dir,dir)+"/CallGraph_20.tar.gz.csv")
        df_temp=df_temp[["service","dm","rt"]]

        if df_all.empty:
            df_all = df_temp
        else:
            df_all = pd.concat([df_all, df_temp])
    out_string="_".join(group_item)
    df_all.groupby(group_item)["rt"].describe().to_csv(get_datas_dir()+f"/statisitc_microservice_{out_string}_rt.csv")


group_item=["dm"]
statistic_microservice_rt(group_item)








